package com.ctshk.sapp.air.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.AirProductChannelType;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.air.dto.*;
import com.ctshk.rpc.air.dto.ticketop.AirBookingTicketTypeOpDTO;
import com.ctshk.rpc.air.req.*;
import com.ctshk.rpc.air.service.IAirProductCostService;
import com.ctshk.rpc.air.service.IAirProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 机票预订中心 前端控制器
 * </p>
 *
 * @author lihang
 * @since 2021-03-05
 */
@Api(value = "机票预订中心", tags = "机票预订中心")
@RestController
@RequestMapping("/air-booking")
public class AirBookingController extends BaseController {

    @DubboReference
    private IAirProductService iAirProductService;

    @DubboReference
    private IAirProductCostService iAirProductCostService;


    @ApiOperation(value = "预订中心推荐列表", notes = "预订中心推荐列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "预订中心推荐列表", operDesc = "预订中心推荐列表")
    @PostMapping(value = "/list-recommend")
    public Result<PageResponse<AirRecommendListDTO>> recommendList(@RequestBody AirProductRecommendListReq req) {

        return iAirProductService.recommendList(req, getCurrentUser(getRequest()));
    }


    @ApiOperation(value = "查询预订列表", notes = "查询预订列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询预订列表", operDesc = "查询预订列表")
    @PostMapping(value = "/list-booking")
    public Result<List<AirBookingListDTO>> bookingList(@RequestBody @Validated AirBookingListReq req) {
        req.setChannelType(AirProductChannelType.SELF_CUSTTOM.getType());
        return iAirProductService.queryBookingList(req, getCurrentUser(getRequest()));
    }


    @ApiOperation(value = "航班一周最低價", notes = "航班一周最低價")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "航班一周最低價", operDesc = "航班一周最低價")
    @PostMapping(value = "/lowprice")
    public Result<List<AirProductPriceDateDTO>> weekLowPrice(@RequestBody @Validated AirLowPriceByDateReq req) {

        return iAirProductCostService.queryAirLowPriceByDate(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询产品成本", notes = "查询产品成本")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询产品成本", operDesc = "查询产品成本")
    @PostMapping(value = "/queryproductcost")
    public Result<List<AirProductPriceDTO>> queryProductCost(@RequestBody @Valid AirProductCostQueryReq req) {

        return Result.success(iAirProductCostService.queryProductCost(req));
    }

    @ApiOperation(value = "机票类型对应的旅客信息", notes = "机票类型对应的旅客信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "机票类型对应的旅客信息", operDesc = "机票类型对应的旅客信息")
    @PostMapping(value = "/queryticketop")
    public Result<List<AirBookingTicketTypeOpDTO>> queryTicketOp() {

        return iAirProductService.queryTicketOp();
    }

}
